/**
 * 鏉冮檺鏍�
 * @authors 鏉庣嚂鍗� (941477276@qq.com)
 * @date    2018-05-27 15:45:12
 */
;(function (window, undefined){
	var count = 0,
		// checkbox璁℃暟鍣�
		inputCount = 0,
		// 瀛樺偍鎵€鏈夌殑YnTree瀵硅薄
		ynTrees = {},
		classNameCfg = {
			// 鑺傜偣灞曞紑鐨刢lassname
			spread: "spread",
			// 鑺傜偣鏀剁缉鐨刢lassname
			shrink: "shrink"
		}
	/**
	 * 鏉冮檺鏍戞瀯閫犲嚱鏁�
	 * @param {dom} ele     鏉冮檺鏍戝鍣�
	 * @param {object} options 鏉冮檺鏍戦厤缃�
	 */
	function YnTree(ele, options){
		if(!ele || !ele.nodeName || (ele.nodeType != 1)){
			throw "YnTree 绗竴涓弬鏁板繀椤绘槸涓€涓厓绱狅紒";
		}
		this.ele = ele;
		var type = YnTree.getType(options);
		
		if(type != "object"){
			throw "YnTree 绗簩涓弬鏁板繀椤绘槸涓€涓璞★紒";
		}
		this.options = options;
		!this.options.data ? this.options.data = [] :"";
		// 濡傛灉鏁版嵁涓嶆槸涓€涓暟缁勶紝鍒欏皢鍏惰浆鎹㈡垚鏁扮粍
		if(YnTree.getType(this.options.data) == "object"){ 
			this.options.data = [this.options.data];
		}
		// 瀛樺偍鑺傜偣鏁版嵁
		this.data = [];
		// 瀛樺偍骞宠鐨勮妭鐐规暟鎹紝鏂逛究鍚庢湡鏌ユ壘鐖跺厓绱�
		this.parallel = [];

		// 瀛樺偍鏈€澶栧眰鐨勬爲缁撴瀯
		
		this.id = "yn_tree" + (++count);
		this.tree = YnTree.createDomByString('<ul class="yn-tree" id="' + this.id + '"></ul>');

		this._init();
	}
	YnTree.prototype._init = function (){
		var that = this;		

		// 濡傛灉娌℃湁鏁版嵁鍒欎笉鐢熸垚dom鍏冪礌锛屼篃涓嶇粍瑁�
		if(this.options.data.length > 0){
			// 鎷疯礉鏁版嵁锛屽皢鐢ㄦ埛浼犻€掕繃鏉ョ殑鑺傜偣鏁版嵁鎷疯礉鍒皌his.data涓紝浠ュ厤姹℃煋鐢ㄦ埛浼犻€掔殑鍘熷鏁版嵁
			this._copyData(this.options.data, this.data);
			
			// 鏍规嵁鏁版嵁鐢熸垚dom鍏冪礌
			this._createDom(this.data);
			// 缁勮dom鍏冪礌
			this._assemblyDom(this.tree, this.data);
		}		

		this.ele.appendChild(this.tree);
		console.log(this);
		ynTrees[this.id] = this;
		return this;
	}
	YnTree.prototype.version = "1.0.0";
	/**
	 * 鎷疯礉鏁版嵁
	 * @param  {array銆乷bject} data 鏁版嵁
	 * @return {object}      this
	 */
	YnTree.prototype._copyData = function (data, parent){
		var that = this;
		data = data || that.options.data;
		YnTree.getType(data) != "array" ? (data = [data]) : "";

		YnTree.forEach(data, function (index, item){
			if(item.children){
				var obj = new CompositeLeaf(item, "composite", that.id);
				parent.push(obj);
				that.parallel.push(obj);
				that._copyData(item.children, obj.children);
			}else{
				var obj = new CompositeLeaf(item, "leaf", that.id);
				parent.push(obj);
				that.parallel.push(obj);
			}			
		});
		
		return this;
	}
	/**
	 * 鍒涘缓dom鍏冪礌
	 * @return {object} object
	 */
	YnTree.prototype._createDom = function (data, parent){
		var that = this;
			///data = this.data;

		YnTree.forEach(data, function (index, item){
			var html = '',
				id = 'yn_tree_input' + (++inputCount),
				nameVal = item.inputName ? item.inputName : "",
				val = item.value ? item.value : "",
				checked = item.checked ? item.checked : false,
				disabled = item.disabled ? item.disabled : false,
				className = item.className ? item.className : "";
			html += '<li class="yn-tree-li shrink" id="' + id + '_li" ' + (parent ? ('pid="' + parent.id + '"') : "") + '>';
			html += '	<div class="checkbox">';
			// edit by Hu Yangdong   2018-09-15   start from this
			/**
			 *  去除所有父节点的checkbox  结合下面对 selectUp(反选) selectDown(全选) 的修改
			 */
			if(item.children){
				html += '<span class="arrow arrow-right"></span>';
			} 
			
			if (item.children) {
				html += '		<label style="display:none!important">';
				html += '			<input type="checkbox" class="yn-tree-input ' + className + '" id="' + id + '" ' + (checked ? 'checked="checked"' : '') + (disabled ? 'disabled="disabled"' : '') + (parent && parent.id ? (' pid="' + parent.id + '"') : "") + ' name="' + nameVal + '" value="' + val + '">'
				html += '		</label>';
			} else {
				html += '		<label>';
				html += '			<input type="checkbox" class="yn-tree-input ' + className + '" id="' + id + '" ' + (checked ? 'checked="checked"' : '') + (disabled ? 'disabled="disabled"' : '') + (parent && parent.id ? (' pid="' + parent.id + '"') : "") + ' name="' + nameVal + '" value="' + val + '">'
				html += '		</label>';
			}
			html += item.name;
			// end here
			if (item.children) {
				console.log(item.children);
			}
			html += '	</div>';
			if(item.children){
				html += '<ul class="yn-tree"></ul>';
				item.type = "composite";
			}else{
				item.type = "leaf";
			}
			html += '</li>';

			item.id = id;
			item.pid = (parent ? parent.id : null);
			item.dom = YnTree.createDomByString(html);


			// 缁欏閫夋缁戝畾change浜嬩欢
			bindChangeEvent(item.dom.querySelector(".yn-tree-input"), item);
			if(item.children){
				// 缁欏睍寮€/鏀剁缉鑺傜偣鐨勪笁瑙掔粦瀹氱偣鍑讳簨浠�
				arrowBindClickEvent(item.dom.querySelector(".arrow-right"), item);
			}
			

			if(item.children){
				that._createDom(item.children, item);
			}

		});

		return this;
	}
	/**
	 * 灏哾om鍏冪礌缁勮璧锋潵
	 * @return {object} this
	 */
	YnTree.prototype._assemblyDom = function(parent, data){
		var that = this;

		if(!parent && !data){
			return this;
		}
		YnTree.getType(data) != "array" ? (data = [data]) : data;

		YnTree.forEach(data, function (index, item){
			parent.appendChild(item.dom);

			if(item.children){
				that._assemblyDom(item.dom.querySelector(".yn-tree"), item.children);
			}
		});

		return this;
	}
	/**
	 * 鏍规嵁id銆佸閫夋鐨勫€兼垨澶嶉€夋璁剧疆澶嶉€夋閫変腑鎴栦笉閫変腑
	 * @param  {stirng銆乨om} condition 闇€瑕侀€変腑鐨刬d銆佸閫夋鐨勫€兼垨澶嶉€夋
	 * @param  {boolean} flag      閫変腑鎴栦笉閫変腑
	 * @return {object}           this
	 */
	YnTree.prototype.select = function (condition, flag){
		var that = this,
			dataItem = null;
		YnTree.forEach(that.parallel, function(index, item){
			var curInput = document.getElementById(item.id);
			if(condition === item.id || condition === item.value || condition === curInput){
				dataItem = item;
				// 修复
				dataItem.select(flag);
				return false;
			} 
		});
		// 此处修改 -->  修复了已选数据不在 tree 节点里  会报错的bug
		// --- Hu Yangdong --2018.09.17
		// dataItem.select(flag);
		return this;
	}
	/**
	 * 鏍规嵁id銆佸閫夋鐨勫€兼垨澶嶉€夋璁剧疆澶嶉€夋鍙敤/涓嶅彲鐢�
	 * @param  {stirng銆乨om} condition id銆佸閫夋鐨勫€兼垨澶嶉€夋
	 * @param  {boolean} flag      鍙敤/涓嶅彲鐢�
	 * @return {object}           this
	 */
	YnTree.prototype.disable = function (condition, flag){
		var that = this,
			dataItem = null;
		YnTree.forEach(that.parallel, function(index, item){
			var curInput = document.getElementById(item.id);
			if(condition === item.id || condition === item.value || condition === curInput){
				dataItem = item;
				return false;
			}
		});
		dataItem.disable(flag);
		return this;
	}
	/**
	 * 鑾峰彇鎵€鏈夐€変腑鐨勫閫夋
	 * @return {array} 杩斿洖鎵€鏈夐€変腑鐨勫閫夋
	 */
	YnTree.prototype.getCheckedInputs = function (){
		var that = this,
			checkedInput = [];
		YnTree.forEach(that.parallel, function (index, item){
			if(item.checked){
				checkedInput.push(document.getElementById(item.id));
			}
		});
		return checkedInput;
	}
	/**
	 * 鑾峰彇鎵€鏈夐€変腑鐨勫閫夋鐨勫€�
	 * @return {array} 杩斿洖鎵€鏈夐€変腑鐨勫閫夋鐨勫€�
	 */
	YnTree.prototype.getValues = function (){
		var that = this,
			checkedVals = [];
		YnTree.forEach(that.getCheckedInputs(), function (index, item){
			checkedVals.push(item.value);
		});
		return checkedVals;
	}
	/**
	 * 閲嶆柊鍒濆鍖栨潈闄愭爲
	 * @return {[type]} [description]
	 */
	YnTree.prototype.reInit = function (data){
		var that = this;		

		if(data && YnTree.getType(data) == "array"){
			this.options.data = data;
		}

		// 濡傛灉娌℃湁鏁版嵁鍒欎笉鐢熸垚dom鍏冪礌锛屼篃涓嶇粍瑁�
		if(this.options.data.length > 0){

			// 灏嗗師鏉ョ殑鏍戣妭鐐圭Щ闄わ紝鐒跺悗鍐嶉噸鏂扮敓鎴愪竴涓�
			this.ele.removeChild(this.tree);
			this.tree = YnTree.createDomByString('<ul class="yn-tree" id="' + this.id + '"></ul>');

			this.data = [];

			// 鎷疯礉鏁版嵁锛屽皢鐢ㄦ埛浼犻€掕繃鏉ョ殑鑺傜偣鏁版嵁鎷疯礉鍒皌his.data涓紝浠ュ厤姹℃煋鐢ㄦ埛浼犻€掔殑鍘熷鏁版嵁
			this._copyData(this.options.data, this.data);
			
			// 鏍规嵁鏁版嵁鐢熸垚dom鍏冪礌
			this._createDom(this.data);
			// 缁勮dom鍏冪礌
			this._assemblyDom(this.tree, this.data);
			this.ele.appendChild(this.tree);
		}
		
		console.log("閲嶆柊鍒濆鍖�");
		return this;
	}
	/**
	 * 閿€姣佸綋鍓嶆爲
	 * @return {undefined} undefined
	 */
	YnTree.prototype.destroy = function (){
		this.ele.removeChild(this.tree);
		this.options = null;
		this.parallel = null;
		this.tree = null;
		this.id = null;
		this.data = null;
		this.ele = null;
		console.info("YnTree閿€姣佸畬姣曪紝寤鸿鎮ㄥ皢YnTree鐨勫疄渚嬬疆涓簄ull锛屽锛歕r\n var ynTree = new YnTree(...);\r\n ynTree.destroy();\r\n ynTree = null;");
	}
	/**
	 * 鏍规嵁id銆佸閫夋鐨勫€兼垨澶嶉€夋璁剧疆鑺傜偣灞曞紑鎴栨敹缂�
	 * @param  {stirng銆乨om} condition id銆佸閫夋鐨勫€兼垨澶嶉€夋
	 * @param  {boolean} flag      灞曞紑鎴栨敹缂�
	 * @return {object}           this
	 */
	YnTree.prototype.spread = function (condition, flag){
		var that = this,
			dataItem = null;
		YnTree.forEach(that.parallel, function(index, item){
			var curInput = document.getElementById(item.id);
			if(condition === item.id || condition === item.value || condition === curInput){
				dataItem = item;
				return false;
			}
		});
		if(dataItem.type == "leaf"){
				return this;
		}
		dataItem.spread(flag);
		return this;
	}

	/**
	 * 鏍规嵁html瀛楃涓插垱寤篸om
	 * @param  {string} htmlStr html瀛楃涓�
	 * @return {dom}         杩斿洖鐢熸垚鐨刣om鍏冪礌
	 */
	YnTree.createDomByString = function (htmlStr){
		var ele = document.createElement("div"),
			dom;
		ele.innerHTML = htmlStr;
		dom = ele.children;
		ele = null;
		return dom[0];
	}
	/**
	 * 鑾峰彇鏁版嵁鐨勬暟鎹被鍨�
	 * @param  {anly} data 闇€瑕佹娴嬬殑鏁版嵁
	 * @return {string}      杩斿洖鑾峰彇鍒扮殑鏁版嵁绫诲瀷
	 */
	YnTree.getType = function (data){
		var type = Object.prototype.toString.call(data);
		return type.replace("[","").replace("]","").split(" ")[1].toLowerCase();
	}
	/**
	 * 閬嶅巻鏁扮粍
	 * @param  {Array} arr 闇€瑕侀亶鍘嗙殑鏁扮粍
	 * @param  {function} fn 閬嶅巻鏃剁殑鍥炶皟
	 * @return {Array}      杩斿洖褰撳墠鏁扮粍
	 */
	YnTree.forEach = function (arr, fn){
		if(YnTree.getType(arr) != "array"){
			return arr;
		}
		for(var i = 0, len = arr.length; i < len; i++){
			var val = fn.call(arr[i], i, arr[i]);
			if(val === false){
				break;
			}
		}
		return arr;
	}
	/**
	 * 缁欐寚瀹氬厓绱犵粦瀹氫簨浠�
	 * @param  {dom}   ele  闇€瑕佺粦瀹氫簨浠剁殑鍏冪礌
	 * @param  {string}   type 浜嬩欢绫诲瀷
	 * @param  {Function} fn   鐐瑰嚮浜嬩欢鍚庣殑鍥炶皟鍑芥暟
	 * @return {dom}        杩斿洖鍏冪礌
	 */
	YnTree.on = function (ele, type, fn){
		if(document.addEventListener){
			ele.addEventListener(type, fn, false);
		}else if(window.attachEvent){
			// 闃叉IE鍚屼竴涓簨浠剁粦瀹氬娆℃椂鎵ц椤哄簭涔辨帀
			if(!ele["_" + type +"_event"]){
				var arr = [fn];
				ele["_" + type +"_event"] = arr;
			}else{
				ele["_" + type +"_event"].push(fn);
			}
			ele.attachEvent("on" + type, function (){
				var e = window.event;
				// 缁熶竴浜嬩欢琛屼负
				e.preventDefault = function (){
					e.returnValue = false;
				}
				e.stopPropagation = function (){
					e.calcleBubble = true;
				}
				e.target = e.srcElement;
				fn.call(ele, e);
			});
		}
		return ele;
	}
	/**
	 * 娴呭眰娆℃嫹璐濆璞�
	 * @param  {objeect} target 鐩爣瀵硅薄
	 * @param  {objeect} obj    
	 * @return {object}        鐩爣瀵硅薄
	 */
	YnTree.extend = function (target, obj){
		for(var attr in obj){
			if(obj.hasOwnProperty(attr)){
				target[attr] = obj[attr];
			}
		}
		return target;
	}


	// 缁欏閫夋缁戝畾chage浜嬩欢
	function bindChangeEvent(input, currentData){
		YnTree.on(input, "change", function (e){
			var curInput = e.target;
			currentData.select(curInput.checked);
		});
	}
	// 缁欏睍寮€/鏀剁缉鑺傜偣鐨勪笁瑙掔粦瀹氱偣鍑讳簨浠�
	function arrowBindClickEvent(arrowEle, currentData){
		YnTree.on(arrowEle, "click", function (e){
			currentData.spread();
		});
	};

	/**
	 * CompositeLeaf瀵硅薄鏋勯€犲嚱鏁�
	 * @param {object} options 缁勫悎瀵硅薄鍙傛暟
	 * @param {string} type 褰撳墠瀵硅薄鐨勭被鍨嬶紝composite琛ㄧず褰撳墠瀵硅薄涓虹粍鍚堝璞★紝缁勫悎瀵硅薄鍙互鏈夊瓙鍏冪礌銆�
	 * leaf琛ㄧず鍙跺瓙瀵硅薄锛屽彾瀛愬璞℃病鏈夊瓙鍏冪礌
	 * @param {object} ynTree 褰撳墠YnTree绫荤殑瀹炰緥瀵硅薄銆傚洜涓篩nTree涓嶤ompositeLeaf鏄袱涓笉鍚岀殑瀵硅薄锛�
	 * 骞朵笖瀹冧滑涔嬮棿蹇呴』鏈夊叧鑱�(浣跨敤杩欑鏂瑰紡浼氶€犳垚寰幆寮曠敤锛岀洰鍓嶆病鏈夋壘鍒版洿濂界殑鏂规硶)
	 */
	function CompositeLeaf(options, type, ynTreeId){
		this.type = type || "";
		YnTree.extend(this, options || {});
		// 灏嗗師鏉ョ殑children娓呯┖
		if(this.children){
			this.children = [];	
		}
		// 涔嬪墠鏄瓨鍌ㄧ殑YnTree瀵硅薄锛岀敱浜庤繖鏍峰瓨鍌ㄤ細閫犳垚寰幆寮曠敤锛屾墍浠ュ悗闈㈡敼涓哄瓨鍌╕nTree鐨処D
		//this.ynTree = ynTree;
		this.ynTreeId = ynTreeId;
	}
	CompositeLeaf.prototype = {
		constructor: CompositeLeaf,
		/**
		 * 鏍戣妭鐐逛竴鐩村悜涓嬮€夋嫨
		 * @param  {boolean} flag 褰撳墠鑺傜偣涓嬬殑鎵€鏈夊瓙鑺傜偣鏄惁鍏ㄩ儴閫変腑
		 * @return {object}      this
		 */
		selectDown: function(flag){
			var that = this;
			flag = !!flag;
			
			if(that.children){
				YnTree.forEach(that.children, function (index, item){
					if(!item.disabled){
						item.checked = flag;
						item.dom.querySelector(".yn-tree-input").checked = flag;
					}
					
					if(item.children){
						YnTree.forEach(item.children, arguments.callee);
					}
				});
			}
			return this;
		},
		/**
		 *  根据业务需求，删除了反选事件  --- by Hu Yangdong  2018-09-15
		 * @param  {boolean} flag  
		 * @return {object}     this
		 */
		selectUp: function(flag){
			// var that = this,
			// 	parent = null;
			// flag = !!flag;

			// if(!this.pid){ return this; }
			// YnTree.forEach(that.getYnTree(that.ynTreeId).parallel, function (index, item){
			// 	//console.log(item.id + "--------" + that.pid);
			// 	if(item.id === that.pid){
			// 		parent = item;
			// 		return false;
			// 	}
			// });

			// /* 缁欑埗绾у厓绱犺缃€変腑涓庡彇娑堥€変腑锛屽綋缁欑埗绾у厓绱犺缃笉閫変腑鏃堕渶鑰冭檻鐖跺厓绱犵殑鎵€鏈夊瓙鍏冪礌鏄惁杩樻湁閫変腑鐨�
			// 锛屽鏋滄湁鍒欎笉鑳界粰鐖剁骇鍏冪礌鍙栨秷鎺� */
			// if(flag){
			// 	parent.checked = flag;
			// 	document.getElementById(parent.id).checked = flag;
			// }else{
			// 	var allChildNotChecked = true;
			// 	YnTree.forEach(parent.children, function (index, item){
			// 		if(item.checked){
			// 			allChildNotChecked = false;
			// 			return false;
			// 		}
			// 	});
			// 	if(allChildNotChecked){
			// 		parent.checked = flag;
			// 		document.getElementById(parent.id).checked = flag;
			// 	}
			// }
			

			// if(parent.pid){
			// 	parent.selectUp(flag);
			// }

			// return this;
		},
		/**
		 * 鏍戣妭鐐归€夋嫨锛屽鏋滃綋鍓嶈妭鐐规湁瀛愯妭鐐癸紝鍒欒皟鐢╯electDown鍚戜笅鏌ユ壘灏嗗綋鍓嶅瓙鑺傜偣鍏ㄩ儴閫変腑鎴栦笉閫変腑锛�
			鐒跺悗璋冪敤selectUp鍚戜笂鏌ユ壘灏嗗綋鍓嶈妭鐐圭殑鎵€鏈夌埗鑺傜偣閮介€変腑鎴栦笉閫変腑
		 * @param  {boolean} flag 褰撳墠鑺傜偣鏄惁閫変腑
		 * @return {object}      this
		 */
		select: function (flag){
			var that = this,
				input = document.getElementById(that.id),
				ynTree = this.getYnTree(this.ynTreeId);
			flag = !!flag;
			if(!that.disabled){
				that.checked = flag;
				input.checked = flag;
			}
			

			// 鎵ц澶嶉€夋鏀瑰彉鍚庣殑鍥炶皟
			ynTree.options.onchange && (YnTree.getType(ynTree.options.onchange) == "function") && ynTree.options.onchange.call(this, input, ynTree);

			/* 灏嗘爲鑺傜偣鐨勬煡鎵惧垎涓轰袱姝ワ紝濡傛灉褰撳墠鑺傜偣鏈夊瓙鑺傜偣锛屽垯璋冪敤selectDown鍚戜笅鏌ユ壘灏嗗綋鍓嶅瓙鑺傜偣鍏ㄩ儴閫変腑鎴栦笉閫変腑锛�
			鐒跺悗璋冪敤selectUp鍚戜笂鏌ユ壘灏嗗綋鍓嶈妭鐐圭殑鎵€鏈夌埗鑺傜偣閮介€変腑鎴栦笉閫変腑 */
			if(typeof ynTree.options.checkStrictly == "undefined" || ynTree.options.checkStrictly === true){
				if(that.type == "composite"){
					this.selectDown(flag);	
				}
				if(that.pid){
					this.selectUp(flag);
				}
			}
			
			return this;
		
		},
		/**
		 * 璁剧疆鑺傜偣涓嶅彲鐢�
		 * @param  {boolean} flag 褰撳墠鑺傜偣鏄惁涓嶅彲鐢�
		 * @return {object}      this
		 */
		disable: function (flag){
			var that = this,
				input = document.getElementById(that.id),
				ynTree = this.getYnTree(this.ynTreeId);
			flag = !!flag;

			that.disabled = flag;
			input.disabled = flag;
			
			return this;
		},
		/**
		 * 鏍规嵁ID鑾峰彇涓庡綋鍓嶅璞″叧鑱旂殑YnTree瀵硅薄
		 * @param  {string} id YnTree瀵硅薄ID
		 * @return {object}    杩斿洖YnTree瀵硅薄
		 */
		getYnTree: function (id){
			var ynTree;
			if(id in ynTrees){
				ynTree = ynTrees[id];
			}
			return ynTree;
		},
		/**
		 * 璁剧疆鑺傜偣灞曞紑鎴栭殣钘�
		 * @param  {boolean} flag 褰撳墠鑺傜偣鏄惁灞曞紑
		 * @return {object}      this
		 */
		spread: function (flag){
			var that = this,
				curLi = document.getElementById(that.id + "_li"),
				ynTree = this.getYnTree(this.ynTreeId),
				classNameArr = curLi.className.split(" "),
				hasSpreadClass = false,
				spreadClassIndex = -1,
				hasShrinkClass = false,
				shrinkClassIndex = -1;


			// 濡傛灉鏄彾瀛愯妭鐐癸紝鍗虫病鏈夊瓙鑺傜偣鍒欑洿鎺ヨ繑鍥�
			if(that.type == "leaf"){
				return this;
			}

			for(var i = 0,len = classNameArr.length; i < len; i++){
				if(classNameArr[i] === classNameCfg.spread){
					hasSpreadClass = true;
					spreadClassIndex = i;
				}
				if(classNameArr[i] === classNameCfg.shrink){
					hasShrinkClass = true;
					shrinkClassIndex = i;
				}
			}

			// 濡傛灉鐢ㄦ埛鏈紶閫抐lag锛屽垯杩涜鑷姩鍒囨崲
			if(typeof flag == "undefined"){
				if(hasSpreadClass){
					flag = false;
				}else if(hasShrinkClass){
					flag = true;
				}
			}

			flag = !!flag;


			if(flag){
				if(hasSpreadClass){return this;}
				// 绉婚櫎鏀剁缉鑺傜偣鐨刢lass
				if(hasShrinkClass){
					classNameArr.splice(shrinkClassIndex, 1);
				}
				classNameArr.push(classNameCfg.spread);
				curLi.className = classNameArr.join(" ");
			}else{
				if(hasShrinkClass){return this;}
				// 绉婚櫎灞曞紑鑺傜偣鐨刢lass
				if(hasSpreadClass){
					classNameArr.splice(spreadClassIndex, 1);
				}
				classNameArr.push(classNameCfg.shrink);
				curLi.className = classNameArr.join(" ");
			}
			
			return this;
		}
		
	}

	window.YnTree = YnTree;
})(window, undefined);